package cn.dankal.flyaudio.presenter;

import java.util.List;

import androidx.annotation.NonNull;
import api.ShopUserServiceFactory;
import cn.dankal.basiclib.pojo.BaseResponse;
import cn.dankal.basiclib.pojo.MyCommentReq;
import cn.dankal.basiclib.rx.AbstractSubscriber;
import cn.dankal.flyaudio.contract.MyCommentContract;
import cn.dankal.flyaudio.friend.pickimage.StringUtil;

/**
 * <pre>
 *     e-mail : junfeng.nie@duntech.com.cn
 *     time   : 22/7/2020
 *     desc   :
 *     version: cn.dankal.flyaudio.presenter
 *     Copyright: Copyright（c）2018
 *     Company:
 * </pre>
 *
 * @author niejunfeng
 */
public class MyCommentPresenter implements MyCommentContract.Presenter {
    private MyCommentContract.View mView;

    @Override
    public void getEvaluate(String orderUuid, String productUuid, String content,
                            String scoreType, List<String> imgList) {
        mView.showLoadingDialog();

        MyCommentReq myCommentReq = new MyCommentReq();
        myCommentReq.setContent(content);
        myCommentReq.setOrderUuid(orderUuid);
        myCommentReq.setProductUuid(productUuid);
        myCommentReq.setScoreType(scoreType);
        if(imgList.size()>0){
            if(imgList.size()==6){
                if(StringUtil.isEmpty(imgList.get(5))){
                    imgList.remove(imgList.get(imgList.size()-1));
                }
            }else{
                imgList.remove(imgList.get(imgList.size()-1));
            }
        }
        myCommentReq.setImgList(imgList);
        ShopUserServiceFactory.comments(myCommentReq)
                .subscribe(new AbstractSubscriber<BaseResponse<Object>>(mView) {
                    @Override
                    public void onNext(BaseResponse<Object> objectBaseResponse) {
                        mView.dismissLoadingDialog();
                        mView.onSuccess();
                    }
                });
    }

    @Override
    public void attachView(@NonNull MyCommentContract.View view) {
        this.mView = view;
    }

    @Override
    public void detachView() {
        this.mView = null;
    }
}
